#cmake的最小版本需求
cmake_minimum_required(VERSION 3.5)

#工程名称a，指定支持的语言
project(cmake_learn VERSION 0.1 LANGUAGES CXX)

#定义变量
# 启用自动UI编译
set(CMAKE_AUTOUIC ON)
# 自动元对象编译
set(CMAKE_AUTOMOC ON)
# 自动资源编译
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 使用cmake没有生成Makefile则使用----> cmake .. -G "Unix Makefiles"
# 参数之间用空格或者分号分开
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network)

#############################ffmpeg###########################
#
#需要写到 qt_add_executable 之前
#
#向工程中加多个特定的头文件搜索路径
#   g++ -I
#   类似qmake中的
#   INCLUDEPATH += D:/software/ffmpeg-6.1.1-full_build-shared/include
# include_directories(D:/software/ffmpeg-6.1.1-full_build-shared/include)
# 相当于 LIBS += -LD:/software/ffmpeg-6.1.1-full_build-shared/lib
# link_directories(D:/software/ffmpeg-6.1.1-full_build-shared/lib)
include_directories(D:/develop/ffmpeg-6.1.1/include)
link_directories(D:/develop/ffmpeg-6.1.1/lib)
# file GLOB命令主要用于匹配规则在指定的目录内匹配到所需要的文件
# file(GLOB FFMPEG_LIBS ${FFMPEG_LIB_DIR}/*.lib)
set(FFMPEG_LIBS avformat avcodec)
#
#############################ffmpeg###########################

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

#变量使用${}取值，在if控制语句中直接使用变量名
#
qt_add_executable(cmake_learn
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
    test_thread.h test_thread.cpp
    udpsocket.h udpsocket.cpp
    tcpsocket.h tcpsocket.cpp
    connector.h connector.cpp
    connectorlist.h connectorlist.cpp

)

#为target添加需要链接的共享库
#相当于 g++ -l
#  -lavformat
#  -lavutil
#将hello动态库文件链接到可执行文件main
# file(GLOB ffmpeg_dylibs ${aaa}/*.lib)
target_link_libraries(cmake_learn PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(cmake_learn PRIVATE Qt${QT_VERSION_MAJOR}::Network)
target_link_libraries(cmake_learn PRIVATE ${FFMPEG_LIBS})

#生成可执行文件
# add_executable(main main.cpp)

set_target_properties(cmake_learn PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS cmake_learn
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(cmake_learn)
endif()

# 生成库文件
# add_library(hello SHARED ${SRC})

#添加编译参数
# add_compile_options(-wall -std=c++11 -o2)
